package org.springblade.modules.platform.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springblade.modules.platform.dto.MeasuringChainPlatformInfoDTO;
import org.springblade.modules.platform.dto.MeasuringChainPlatformTypeDTO;
import org.springblade.modules.platform.dto.MeasuringChainTableDTO;
import org.springblade.modules.platform.dto.SynchronizeDataDTO;
import org.springblade.modules.platform.entity.*;
import org.springblade.modules.platform.props.HuatengProperties;
import org.springblade.modules.platform.service.*;
import org.springblade.modules.platform.vo.*;
import org.springblade.modules.platform.vo.enums.DeptCategoryEnum;
import org.springblade.modules.platform.vo.enums.ProductTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SYG
 * @since 2023-05-22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/service-huateng-sxdb/measuringChainTable")
@Api(value = "", tags = "新版本测量链管理")
@Slf4j
public class MeasuringChainTableController {
    private final IMeasuringPlatformConfigService iMeasuringPlatformConfigService;
    private final IMeasuringChainTableService iMeasuringChainTableService;
    private final IMeasuringCompanyInfoService iMeasuringCompanyInfoService;
    private final IMeasuringChainInfoService iMeasuringChainInfoService;
    private final IMeasuringChainPlatformTypeService iMeasuringChainPlatformTypeService;
    private final IMeasuringPlatformTypeService iMeasuringPlatformTypeService;
    private final IMeasuringChainPlatformInfoService iMeasuringChainPlatformInfoService;
    private final IDeviceTableService iDeviceTableService;
    private static RestTemplate restTemplate = new RestTemplate();
    private final HuatengProperties huatengProperties;

    @PostMapping(value = "/install")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "传入deptInfoTableDTO")
    public R add(@RequestBody MeasuringChainTableDTO measuringChainTableDTO){
        iMeasuringChainTableService.insertMeasuringChainTable(measuringChainTableDTO);
        return R.success("成功");
    }
    @GetMapping("/tree")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "树", notes = "")
    public R<List<DeptInfoTableTreeVO>> tree() {
        List<MeasuringChainTable> list = iMeasuringChainTableService.list(Wrappers.<MeasuringChainTable>query().lambda().eq(MeasuringChainTable::getIsDeleted,0).orderByAsc(MeasuringChainTable::getSort));
        if(CollectionUtils.isEmpty(list)){
            return R.data(null);
        }
        List<DeptInfoTableTreeVO> collect = list.stream().map(x -> DeptInfoTableTreeVO.builder()
                .deptCategory(x.getChainCategory())
                .deptName(x.getChainName())
                .id(x.getId())
                .parentId(x.getParentId()).remark(x.getRemark()).build()).collect(Collectors.toList());
        List<DeptInfoTableTreeVO> collect1 = collect.stream().filter(m -> m.getParentId()==0).peek((m) -> m.setChildrenList(getChildrens(m, collect))).collect(Collectors.toList());
        return R.data(collect1);
    }
    private static List<DeptInfoTableTreeVO> getChildrens(DeptInfoTableTreeVO root, List<DeptInfoTableTreeVO> all) {
        return all.stream().filter(m -> Objects.equals(m.getParentId(), root.getId())).peek(
                (m) -> m.setChildrenList(getChildrens(m, all))
        ).collect(Collectors.toList());
    }
    @DeleteMapping("/remove/{id}")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除", notes = "传入id")
    public R remove(@PathVariable Long id){
        iMeasuringChainTableService.removeMeasuringChain(id);
        return R.success("成功");
    }
    @PutMapping(value = "/update")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "编辑", notes = "传入deptInfoTableDTO")
    public R edit(@RequestBody MeasuringChainTableDTO measuringChainTableDTO) {
        iMeasuringChainTableService.upateMeasuringChainTable(measuringChainTableDTO);
        if(Objects.equals(DeptCategoryEnum.MEASURING.getCode(), measuringChainTableDTO.getChainCategory())){
            try {
                synchronizeData(measuringChainTableDTO.getId());
            }catch (Exception e){
                log.info("调用异常");

            }
        }
        return R.success("成功");
    }
    @GetMapping("/listMeasuringPlatform")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "侧台列表下拉框", notes = "")
    public R<List<MeasuringPlatformType>> list() {
        List<MeasuringPlatformType> list = iMeasuringPlatformTypeService.list(Wrappers.<MeasuringPlatformType>query().lambda().eq(MeasuringPlatformType::getIsDeleted, 0));
        return R.data(list);
    }
    @GetMapping("/info")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "点击左边树", notes = "")
    public R<List<MeasuringChainTableVO>> getInfo(@RequestParam(value = "id",required = false) Long id,
                     @RequestParam(value = "chainName",required = false) String chainName) {
        QueryWrapper<MeasuringChainTable> queryWrapper = new QueryWrapper<>();
        if(id!=null){
            queryWrapper.lambda().eq(MeasuringChainTable::getParentId,id);
        }
        if(!StringUtils.isEmpty(chainName)){
            queryWrapper.lambda().like(MeasuringChainTable::getChainName,chainName);
        }
        List<MeasuringChainTable> list = iMeasuringChainTableService.list(queryWrapper);
        if(!CollectionUtils.isEmpty(list)){
            List<MeasuringChainTableVO> collect = list.stream().map(x -> {
                MeasuringChainTableVO measuringChainTableVO = new MeasuringChainTableVO();
                BeanUtil.copy(x, measuringChainTableVO);
                switch (Objects.requireNonNull(DeptCategoryEnum.getEnum(x.getChainCategory()))) {
                    case COMPANY:
                        MeasuringChainTableVO.MeasuringCompanyInfoVO measuringCompanyInfoVO = new MeasuringChainTableVO.MeasuringCompanyInfoVO();
                        MeasuringCompanyInfo one = iMeasuringCompanyInfoService.getOne(Wrappers.<MeasuringCompanyInfo>query().lambda().eq(MeasuringCompanyInfo::getMeasuringChainId, x.getId()));
                        BeanUtil.copy(one, measuringCompanyInfoVO);
                        measuringChainTableVO.setMeasuringCompanyInfoVO(measuringCompanyInfoVO);
                    case MEASURING:
                        MeasuringChainTableVO.MeasuringChainInfoVO measuringChainInfoVO = new MeasuringChainTableVO.MeasuringChainInfoVO();
                        MeasuringChainInfo one1 = iMeasuringChainInfoService.getOne(Wrappers.<MeasuringChainInfo>query().lambda().eq(MeasuringChainInfo::getMeasuringChainId, x.getId()));
                        BeanUtil.copy(one1, measuringChainInfoVO);
                        measuringChainTableVO.setMeasuringChainInfoVO(measuringChainInfoVO);
                }
                return measuringChainTableVO;

            }).collect(Collectors.toList());
            return R.data(collect);
        }else {
            return R.data(null);
        }
    }
    @GetMapping("/infoByIdDirection")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据测量连ID查询测量连方向", notes = "")
    public R<List<MeasuringChainPlatformType>> infoByIdDirection(@RequestParam(value = "id",required = false) Long id) {
        return R.data(iMeasuringChainPlatformTypeService.list(Wrappers.<MeasuringChainPlatformType>query().lambda()
                .eq(MeasuringChainPlatformType::getMeasuringChainId, id))) ;
    }
    @GetMapping("/listGraphics")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "侧台列表图形", notes = "传入deviceTablePageDTO")
    public R<JSONObject> listGraphics(@RequestParam(value = "id",required = false) Long id,
                                      @RequestParam(value = "measuringTypeCode")Integer measuringTypeCode) {
        MeasuringChainPlatformType measuringChainPlatformType = iMeasuringChainPlatformTypeService.getOne(Wrappers.<MeasuringChainPlatformType>query().lambda()
                .eq(MeasuringChainPlatformType::getMeasuringChainId, id)
                .eq(MeasuringChainPlatformType::getMeasuringTypeCode, measuringTypeCode));
        if(measuringChainPlatformType==null){
            return R.data(null);
        }
        List<MeasuringChainPlatformInfo> list = iMeasuringChainPlatformInfoService.list(Wrappers.<MeasuringChainPlatformInfo>query().lambda().eq(MeasuringChainPlatformInfo::getMeasuringTypeId, measuringChainPlatformType.getId()));
        JSONObject jsonObject = new JSONObject();
        List<MeasuringChainPlatformInfoGraphicalVO> list1 = new ArrayList<>();

        list.forEach(x->{
			MeasuringChainPlatformInfoGraphicalVO measuringChainPlatformInfoGraphicalVO = new MeasuringChainPlatformInfoGraphicalVO();
            BeanUtil.copy(x, measuringChainPlatformInfoGraphicalVO);
            measuringChainPlatformInfoGraphicalVO.setxAxis(x.getxAxis());
            measuringChainPlatformInfoGraphicalVO.setyAxis(x.getyAxis());
            measuringChainPlatformInfoGraphicalVO.setX(x.getxCoordinate());
            measuringChainPlatformInfoGraphicalVO.setY(x.getyCoordinate());
            measuringChainPlatformInfoGraphicalVO.setDelete(false);
            measuringChainPlatformInfoGraphicalVO.setDelete(Objects.equals(x.getSort(), list.size()-1));
            list1.add(measuringChainPlatformInfoGraphicalVO);
        });
        jsonObject.put("measuringChain",list1);
        return R.data(jsonObject);
    }
    @GetMapping("/infoById")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据测量连ID配置的侧台列表带分页", notes = "")
    public R<MeasuringChainPlatformTypeVO> infoById(@RequestParam(value = "id",required = false) Long id,
                                                    @RequestParam(value = "measuringTypeCode")Integer measuringTypeCode,
                                                    @RequestParam(value = "measuringPlatformName",required = false)String measuringPlatformName,
                                                    Query query) {
        MeasuringChainPlatformTypeVO measuringChainPlatformTypeVO = new MeasuringChainPlatformTypeVO();
        measuringChainPlatformTypeVO.setMeasuringTypeCode(measuringTypeCode);
        IPage<MeasuringChainPlatformInfo> listByPage = iMeasuringChainPlatformTypeService.getListByPage(measuringTypeCode, id, measuringPlatformName, query);
        if(listByPage==null){
            return R.data(measuringChainPlatformTypeVO);
        }
        MeasuringChainTable byId = iMeasuringChainTableService.getById(id);
        List<MeasuringChainPlatformInfo> records = listByPage.getRecords();
        measuringChainPlatformTypeVO.setTotal(listByPage.getTotal());
        List<MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO> collect = records.stream().map(x -> {
            MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO measuringChainPlatformInfoVO = new MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO();
            BeanUtil.copy(x, measuringChainPlatformInfoVO);
            measuringChainPlatformInfoVO.setxAxis(x.getxAxis());
            measuringChainPlatformInfoVO.setyAxis(x.getyAxis());
            int i = Integer.parseInt(String.valueOf(listByPage.getTotal()));
            measuringChainPlatformInfoVO.setDelete(Objects.equals(x.getSort(), i-1));
            measuringChainPlatformInfoVO.setMeasuringTypeCode(measuringTypeCode);
            measuringChainPlatformInfoVO.setChainName(byId.getChainName());
            return measuringChainPlatformInfoVO;
        }).collect(Collectors.toList());
        measuringChainPlatformTypeVO.setMeasuringChainPlatformInfoVOS(collect);
        return R.data(measuringChainPlatformTypeVO);
    }
    @PutMapping(value = "/updateMeasuringPlatform")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "编辑测量连方向配置侧台", notes = "传入measuringChainPlatformTypeDTO")
    public R updateMeasuringPlatform(@RequestBody MeasuringChainPlatformInfoDTO measuringChainPlatformInfoDTO){
        iMeasuringChainPlatformTypeService.updataMeasuringChainPlatformType(measuringChainPlatformInfoDTO);
        return R.success("成功");
    }
    @GetMapping("/fatherPlatform")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "测量连配置侧台时候查询父亲侧台(传入测量连方向的ID)", notes = "")
    public R<MeasuringPlatformType> fatherPlatform(@RequestParam(value = "id") Long id) {
        if(id==null){
            return R.data(null);
        }
        MeasuringPlatformType fatherPlatform = iMeasuringChainPlatformTypeService.getFatherPlatform(id);
        return R.data(fatherPlatform);
    }
    @PostMapping(value = "/addMeasuringPlatform")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "测量连配置侧台(如果返回ID，下次添加ID带入)", notes = "传入measuringChainPlatformTypeDTO")
    public R<Long> addMeasuringPlatform(@RequestBody MeasuringChainPlatformTypeDTO measuringChainPlatformTypeDTO){
        Long aLong = iMeasuringChainPlatformTypeService.installMeasuringChainPlatformType(measuringChainPlatformTypeDTO);
        try {
            synchronizeData(measuringChainPlatformTypeDTO.getMeasuringChainId());
        }catch (Exception e){
            log.info("调用异常");

        }
        return R.data(aLong);
    }
    @DeleteMapping("/removeSideSill/{id}")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "删除测量量配置的某个侧台下的正向配置或者逆向配置(传入配置的ID)", notes = "传入配置")
    public R removeSideSill(@PathVariable Long id){
        iMeasuringChainPlatformTypeService.removeSideSill(id);

        return R.success("成功");
    }
    @DeleteMapping("/removePlatforml/{id}")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "删除测量连配置的侧台", notes = "传入配置")
    public R removePlatforml(@PathVariable Long id){
        iMeasuringChainPlatformInfoService.removeById(id);
        return R.success("成功");
    }


    @DeleteMapping("/removeMeasuringPlatform/{id}")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "测量连删除测量连方向(传入本测量连方向的ID)", notes = "传入id")
    public R removeMeasuringPlatform(@PathVariable Long id){
        iMeasuringChainPlatformTypeService.deleteMeasuringChainPlatformType(id);
        return R.success("成功");
    }
    @GetMapping("/infoByIdConfig")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据测量连配置侧台详情(传入配置的ID)", notes = "")
    public R<MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO> infoByIdConfig(@RequestParam(value = "id",required = false) Long id) {
        MeasuringChainPlatformInfo byId = iMeasuringChainPlatformInfoService.getById(id);
        MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO measuringChainPlatformInfoVO = new MeasuringChainPlatformTypeVO.MeasuringChainPlatformInfoVO();
        BeanUtil.copy(byId, measuringChainPlatformInfoVO);
        measuringChainPlatformInfoVO.setX(byId.getxCoordinate());
        measuringChainPlatformInfoVO.setY(byId.getyCoordinate());
        return R.data(measuringChainPlatformInfoVO) ;
    }
    private void synchronizeData(Long measuringChainId){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",measuringChainId);
        MeasuringChainInfo one = iMeasuringChainInfoService.getOne(Wrappers.<MeasuringChainInfo>query().lambda().eq(MeasuringChainInfo::getMeasuringChainId, measuringChainId));
        jsonObject.put("isSelf", one.getIsSelf() ?1:0);
        jsonObject.put("isLightSource", one.getIsLightSource() ?1:0);
        jsonObject.put("intervalTime",one.getIntervalTime());
        jsonObject.put("pressure", one.getPressure());
        jsonObject.put("pressureScope",one.getPressureScope());
        String[] split = one.getVacuumPumpId().split(",");
        String  vacuumPumpId = "";
        for (String s : split) {
            DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
            vacuumPumpId = vacuumPumpId + l.getDeviceChannelId() + ",";

        }
        vacuumPumpId = vacuumPumpId.substring(0, vacuumPumpId.length() - 1);
        jsonObject.put("deviceId",vacuumPumpId);
        List<MeasuringChainPlatformType> list = iMeasuringChainPlatformTypeService.list(Wrappers.<MeasuringChainPlatformType>query().lambda().eq(MeasuringChainPlatformType::getMeasuringChainId, measuringChainId));
        if (Func.isEmpty(list)){
            return;
        }
        List<SynchronizeDataDTO> jsonObjects = new ArrayList<>();
        for (MeasuringChainPlatformType measuringChainPlatformType : list) {
            List<MeasuringChainPlatformInfo> list1 = iMeasuringChainPlatformInfoService.list(Wrappers.<MeasuringChainPlatformInfo>query().lambda().eq(MeasuringChainPlatformInfo::getMeasuringTypeId, measuringChainPlatformType.getId()));
            if (Func.isEmpty(list1)){
                return;
            }
            List<Long> collect = list1.stream().map(MeasuringChainPlatformInfo::getMeasuringPlatformId).collect(toList());
            List<MeasuringPlatformType> list2 = iMeasuringPlatformTypeService.list(Wrappers.<MeasuringPlatformType>query().lambda().in(MeasuringPlatformType::getId, collect));
            if (Func.isEmpty(list2)){
                return;
            }

            List<Long> collect4 = list2.stream().map(MeasuringPlatformType::getId).collect(toList());
            List<MeasuringPlatformConfig> list5 = iMeasuringPlatformConfigService.list(Wrappers.<MeasuringPlatformConfig>query().lambda().in(MeasuringPlatformConfig::getMeasuringPlatformId, collect4));
            list5.forEach(x->{
                Integer integer = x.getxType();
                if(integer!=null&&integer==2){
                    String s = x.getxValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
                Integer integer1 = x.getyType();
                if(integer1!=null&&integer1==2){
                    String s = x.getyValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId( Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
                Integer integer2 = x.getzType();
                if(integer2!=null&&integer2==2){
                    String s = x.getzValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId( Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
                Integer alphaType = x.getAlphaType();
                if(alphaType!=null&&alphaType==2){
                    String s = x.getAlphaValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
                Integer betaType = x.getBetaType();
                if(betaType!=null&&betaType==2){
                    String s = x.getBetaValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
                Integer gamaType = x.getGamaType();
                if(gamaType!=null&&gamaType==2){
                    String s = x.getBetaValue();
                    DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, s).eq(DeviceTable::getIsDeleted,0));
                    SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                    jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
                    jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                    jsonObjects.add(jsonObject2);
                }
            });
            List<String> collect3 = list2.stream().map(MeasuringPlatformType::getDeviceId).collect(toList());
            collect3.forEach(x->{
                if(x.contains(",")){
                    List<String> list3 = Arrays.asList(x.split(","));
                    List<DeviceTable> list4 = iDeviceTableService.list(Wrappers.<DeviceTable>query().lambda().in(DeviceTable::getDeviceId, list3));
                    list4.forEach(l->{
                        SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                        jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
                        jsonObject2.setType( Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                        jsonObjects.add(jsonObject2);
                    });
                }else {
                    List<DeviceTable> list4 = iDeviceTableService.list(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId, x));
                    list4.forEach(l->{
                        SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
                        jsonObject2.setDeviceId( Integer.parseInt(l.getDeviceChannelId()));
                        jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
                        jsonObjects.add(jsonObject2);
                    });
                }
            });

	     List<String> collect5 = list2.stream().map(MeasuringPlatformType::getCoordinatChannelId).collect(toList());
		 if(Func.isNotEmpty(collect5)){
			 collect5.forEach(x->{
				 String[] split1 = x.split(",");
				 for (String s : split1) {
					 DeviceTable l = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceChannelId, s).eq(DeviceTable::getIsDeleted,0));
					 SynchronizeDataDTO jsonObject2 = new SynchronizeDataDTO();
					 jsonObject2.setDeviceId(Integer.parseInt(l.getDeviceChannelId()));
					 jsonObject2.setType(Objects.requireNonNull(ProductTypeEnum.getEnum(l.getProductId())).getMsg());
					 jsonObjects.add(jsonObject2);
				 }

			 });

		 }

        }
        List<SynchronizeDataDTO> collect1 = jsonObjects.stream().sorted(Comparator.comparing(SynchronizeDataDTO::getDeviceId)).distinct().collect(toList());
        jsonObject.put("equipmentList", collect1);
        HttpEntity<JSONObject> httpEntity = new HttpEntity<>(jsonObject,new HttpHeaders());
        restTemplate.exchange(huatengProperties.getSaveDevice(), HttpMethod.POST, httpEntity, String.class);
    }
    @GetMapping("/vacuumPumpList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "真空泵下拉框", notes = "传入deviceTablePageDTO")
    public R<List<DeviceTable>> highDeviceTablelist() {
        List<DeviceTable> list1 = iDeviceTableService.list(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getIsDeleted, 0)
                .eq(DeviceTable::getProductId, "HT-VACUUM-PUMP"));
        return R.data(list1);
    }
    @ApiLog("测量连下拉框")
    @GetMapping("/getMeasuringChainList")
    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "测量连下拉框", notes = "传入productType")
    public R<List<MeasuringChainTable>> getMeasuringChainTableList() {
        List<MeasuringChainTable> list = iMeasuringChainTableService.list(new QueryWrapper<MeasuringChainTable>().lambda()
                .eq(MeasuringChainTable::getChainCategory, 2)
                .eq(MeasuringChainTable::getIsDeleted, 0));
        return R.data(list);
    }
}

